package com.example.demo1.repository;

import com.example.demo1.domain.Picture;
import com.example.demo1.utils.IndiExper;
import org.hibernate.sql.Select;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.data.jpa.repository.Modifying;
import java.util.List;
import java.util.Optional;

@Repository
public interface PictureDao extends JpaRepository<Picture, Long> {
    @Query("SELECT new  com.example.demo1.utils.IndiExper(p.experiment_name, p.team_name, p.picture_name) " +
            "FROM Picture p WHERE p.username = :username")
    List<IndiExper> findByUsername(@Param("username") String username);

    @Query("DELETE FROM Picture p WHERE p.experiment_name = :experiment_name " +
            "AND p.picture_name = :picture_name " +
            "AND p.team_name = :team_name")
    void deletePictureByExperimentNameAndPictureNameAndTeamName(
            @Param("experiment_name") String experiment_name,
            @Param("picture_name") String picture_name,
            @Param("team_name") String team_name);
    @Query("SELECT p.picture FROM Picture p WHERE p.experiment_name = :experiment_name " +
            "AND p.picture_name = :picture_name " +
            "AND p.team_name = :team_name")
    String findPictureByExperimentNameAndPictureNameAndTeamName(
            @Param("experiment_name") String experiment_name,
            @Param("picture_name") String picture_name,
            @Param("team_name") String team_name);
}

